<%@ page contentType="text/html;charset=UTF-8" %>
<%@ include file="/WEB-INF/views/include/taglib.jsp"%>
<html>
<head>
	<title>用户管理</title>
	<meta name="decorator" content="default"/>
	<script type="text/javascript">
		$(document).ready(function() {
			
			layui.use(['laypage', 'form','table'], function(){
				var table = layui.table;
				//table.render();
				//转换静态表格
				table.init('user', {
				  height: 315 //设置高度
				  ,limit: 10 //注意：请务必确保 limit 参数（默认：10）是与你服务端限定的数据条数一致
				  //支持所有基础参数
				}); 
				  var form = layui.form; //只有执行了这一步，部分表单元素才会自动修饰成功
				  form.render();
				  var laypage = layui.laypage;
				  laypage.render({
					  elem: 'pageDiv',
					  count: ${page.count} //数据总数，从服务端得到
					  ,curr:${page.pageNo}
					  ,limit:30
					  ,layout: ['prev', 'page', 'next', 'count']
					  ,jump: function(obj, first){
					    //obj包含了当前分页的所有参数，比如：
					   // console.log(obj.curr); //得到当前页，以便向服务端请求对应页的数据。
					   // console.log(obj.limit); //得到每页显示的条数
					    
					    //首次不执行
					    if(!first){
					    	$("#firstPage").val(false);
					    	page(obj.curr,obj.limit);
					    }
					  }
					});
				  var table = layui.table;
					table.init('userTable',{limit:30});
				}); 
			
			$("#btnExport").click(function(){
				top.$.jBox.confirm("确认要导出用户数据吗？","系统提示",function(v,h,f){
					if(v=="ok"){
						$("#searchForm").attr("action","${ctx}/sys/user/export");
						$("#searchForm").submit();
					}
				},{buttonsFocus:1});
				top.$('.jbox-body .jbox-icon').css('top','55px');
			});
			$("#btnImport").click(function(){
				$.jBox($("#importBox").html(), {title:"导入数据", buttons:{"关闭":true}, 
					bottomText:"导入文件不能超过5M，仅允许导入“xls”或“xlsx”格式文件！"});
			});
		});
		function page(n,s){
			if(n) $("#pageNo").val(n);
			if(s) $("#pageSize").val(s);
			$("#searchForm").attr("action","${ctx}/sys/user/list");
			$("#searchForm").submit();
	    	return false;
	    }
	</script>
</head>
<body style="padding: 10px;">
	<div id="importBox" class="layui-hide">
		<form id="importForm" action="${ctx}/sys/user/import" method="post" enctype="multipart/form-data"
			class="form-search" style="padding-left:20px;text-align:center;" onsubmit="loading('正在导入，请稍等...');"><br/>
			<input id="uploadFile" name="file" type="file" style="width:330px"/><br/><br/>　　
			<input id="btnImportSubmit" class="btn btn-primary" type="submit" value="   导    入   "/>
			<a href="${ctx}/sys/user/import/template">下载模板</a>
		</form>
	</div>
	<div class="layui-tab layui-tab-brief" lay-filter="docDemoTabBrief">
	<ul class="layui-tab-title">
		<li class="layui-this"><a href="${ctx}/sys/user/list">用户列表</a></li>
		<shiro:hasPermission name="sys:user:edit"><li><a href="${ctx}/sys/user/form">用户添加</a></li></shiro:hasPermission>
	</ul>
	 <div class="layui-tab-content"></div>
	</div>
	<div class="layui-input-block" style="width:1050px; margin-left: 0;">
	<form:form id="searchForm" modelAttribute="user" action="${ctx}/sys/user/list" method="post" class="layui-form">
		<input id="pageNo" name="pageNo" type="hidden" value="${page.pageNo}"/>
		<input id="pageSize" name="pageSize" type="hidden" value="${page.pageSize}"/>
		<sys:tableSort id="orderBy" name="orderBy" value="${page.orderBy}" callback="page();"/>
		<blockquote class="layui-elem-quote quoteBox">
	        <form class="layui-form">
				<div class="layui-inline">
					<label class="layui-form-label">归属公司：</label>
					<div class="layui-input-block">
						<sys:treeselect id="company" name="company.id" value="${user.company.id}" labelName="company.name" labelValue="${user.company.name}" 
				title="公司" url="/sys/office/treeData?type=1" cssClass="layui-input" allowClear="true" notAllowSelectParent="true" checked="true" hideBtn="true"/>
		 			</div>
				</div>
				<div class="layui-inline">
					<label class="layui-form-label">登录名：</label>
					<div class="layui-input-inline">
						<form:input path="loginName" htmlEscape="false" maxlength="50" class="layui-input" type="text"/>
			 		</div>
				</div>
				<div class="layui-inline">
					<label class="layui-form-label">归属部门：</label>
					<div class="layui-input-block">
						<sys:treeselect id="office" name="office.id" value="${user.office.id}" labelName="office.name" labelValue="${user.office.name}" 
				title="部门" url="/sys/office/treeData?type=2" cssClass="layui-input" allowClear="true" notAllowSelectParent="true" checked="true" hideBtn="true"/>
					</div>
				</div>
			<div class="layui-inline">
				<label class="layui-form-label">姓&nbsp;&nbsp;&nbsp;名：</label>
				<div class="layui-input-inline">
					<form:input path="name" htmlEscape="false" maxlength="50" class="layui-input" type="text"/>
				</div>
			</div>
				<input id="btnSubmit" class="layui-btn search_btn" type="submit" value="查询" onclick="return page();"/>
				<input id="btnExport" class="layui-btn search_btn" type="button" value="导出"/>
				<input id="btnImport" class="layui-btn search_btn" type="button" value="导入"/>
			</form>
	    </blockquote>
	</form:form>

	<sys:message content="${message}"/>
	<table id="contentTable" class="layui-table" lay-filter="userTable" style="align:right">
		<thead>
			<tr>
				<th style="width:150" lay-data="{field:'companyname'}">归属公司</th>
				<th style="width:150" lay-data="{field:'officename'}">归属部门</th>
				<th style="width:150" lay-data="{field:'loginName'}">登录名</th>
				<th style="width:150" lay-data="{field:'name'}">姓名</th>
				<th style="width:150" lay-data="{field:'phone'}">电话</th>
				<th style="width:150" lay-data="{field:'mobile'}">手机</th> 
				<shiro:hasPermission name="sys:user:edit">
				<th style="width:150" lay-data="{field:'操作'}">操作</th>
				</shiro:hasPermission>
			</tr>
		</thead>
		<tbody>
		<c:forEach items="${page.list}" var="user">
			<tr>
				<td>${user.company.name}</td>
				<td>${user.office.name}</td>
				<td><a class="layui-blue" href="${ctx}/sys/user/form?id=${user.id}">${user.loginName}</a></td>
				<td>${user.name}</td>
				<td>${user.phone}</td>
				<td>${user.mobile}</td><%--
				<td>${user.roleNames}</td> --%>
				<shiro:hasPermission name="sys:user:edit"><td>
    				<a class="layui-btn layui-btn-xs" lay-event="edit" href="${ctx}/sys/user/form?id=${user.id}">修改</a>
					<a class="layui-btn layui-btn-danger layui-btn-xs" lay-event="del" href="${ctx}/sys/user/delete?id=${user.id}" onclick="return confirmx('确认要删除该用户吗？', this.href)">删除</a>
				</td></shiro:hasPermission>
			</tr>
		</c:forEach>
		</tbody>
	</table>
		</div>
	<div id="pageDiv" class="pagination layui-elem-field layui-field-title">${page}</div>
</body>
</html>